package com.tmc.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.tmc.bean.common.ContextInfo;
import com.tmc.bean.common.Pagination;
import com.tmc.entity.common.EthInterfaceVendor;
import com.tmc.util.ObjectUtil;

@Repository
public class EthInterfaceVendorDaoImpl extends BaseDaoImpl<EthInterfaceVendor> {

	public Pagination<EthInterfaceVendor> findByCon(ContextInfo context, EthInterfaceVendor cond, int pageIndex, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from EthInterfaceVendor c where c.enabledFlag = 'Y' ");
		if (ObjectUtil.hasText(cond.getVendorCode())) {
			sql.append(" and (c.vendorCode = :vendorCode or c.vendorName like :vendorCode) ");
			params.put("vendorCode", "%" + cond.getVendorCode() + "%");
		}
		sql.append(" order by c.lastUpdateDate desc ");
		return this.findPagination(sql.toString(), params, pageIndex, pageSize);
	}

	public List<EthInterfaceVendor> findAll(ContextInfo context) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from EthInterfaceVendor c where c.enabledFlag = 'Y' ");
		return this.findList(sql.toString(), params);
	}
	
	public EthInterfaceVendor getByCode(ContextInfo context, String vendorCode) {
		if (!ObjectUtil.hasText(vendorCode)) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from EthInterfaceVendor c where c.enabledFlag = 'Y' ");
		sql.append(" and c.vendorCode = :vendorCode ");
		params.put("vendorCode", vendorCode);
		return this.get(sql.toString(), params);
	}

}
